<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<script>
// Promise静态方法
// Promise.race([p1,p2,p3])返回一个新的Promsie对象（p4）
// p4跟随p1,p2,p3最先完成的Promsie对象的状态和结果（竞速模式）

let p1 = new Promise((resolve,reject)=>{
    setTimeout(()=>{
        console.log( '任务 1' );
        resolve(11);
    },1234);
});
let p2 = new Promise((resolve,reject)=>{
    setTimeout(()=>{
        console.log( '任务 2' );
        // resolve(22);
        reject(77);
    },834);
});
let p3 = new Promise((resolve,reject)=>{
    setTimeout(()=>{
        console.log( '任务 3' );
        resolve(33);
    },1234);
});

Promise.race([p1,p2,p3])// p4
.then(
    (res)=>{
        console.log( 'p4成功',res );
    },
    (res)=>{
        console.log( 'p4失败',res );
    }
)

</script>
</body>
</html>